  package com.example.youhuo.utils

import android.app.Dialog
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import com.example.myapplication.R
import kotlinx.android.synthetic.main.antivity_dialog.*
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import java.security.AccessControlContext

class Custom_Dialog(context: Context) : Dialog(context) {
    var customDialog: Custom_Dialog? = null
    var agreeclick: agreeOnClick? = null
    var disagreeclick: disagreeOnClick? = null

    fun create_Dialog() {
        var custom_dialog = LayoutInflater.from(context).inflate(R.layout.antivity_dialog, null)
        customDialog = Custom_Dialog(context)
        var agree = custom_dialog.findViewById<TextView>(R.id.dialog_agree)
        var disagree = custom_dialog.findViewById<TextView>(R.id.dialog_disagree)
        //展示dialog
        customDialog!!.addContentView(
            custom_dialog, LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT
            )
        )
        customDialog!!.show()
        //文字的点击
        agree.setOnClickListener(View.OnClickListener {

            customDialog!!.dismiss()
            GlobalScope.launch {
                delay(3000)
                agreeclick!!.agreeOnClickListener()
            }
        })
        disagree.setOnClickListener(View.OnClickListener {
            disagreeclick!!.disagreeOnClickListener()
            customDialog!!.dismiss()
        })



    }
    fun getagreeOnClick(agreeOnClick: agreeOnClick) {
        this.agreeclick = agreeOnClick
    }

    fun getdisagreeOnClick(disagreeOnClick: disagreeOnClick) {
        this.disagreeclick = disagreeOnClick
    }

    //接口回调
    interface agreeOnClick {
        fun agreeOnClickListener()
    }

    interface disagreeOnClick {
        fun disagreeOnClickListener()
    }



}